import Vue from 'vue'
import Vuex from 'vuex'
import message from '../utils/message'
import router from '@/router'
import cookie from  'vue-cookies'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
      vuexindex:0,
      userInfo:'',
      token:"",
      token:undefined,
  },
  getters: {

  },
  mutations: {
    updateUserMessage(state,message){
      console.log(message)
      state.userInfo=message
    },
    setUserToken(state,token){
      state.token = token || ""
      if(token == ""|| token == null || token == undefined){
        sessionStorage.removeItem("token")
        sessionStorage.removeItem("token")
        cookie.remove("token")
      }else{
        sessionStorage.setItem("token",token)
        cookie.set("token",token,60*60)
        state.token=token
        // this.$cookies.set("toekn",token)
      }
    },
    logout(state){
      router.replace("/login")
      sessionStorage.removeItem("token")
      cookie.remove("token")
    },
    clearOpenedSubmenu(state){
      if(this.state.token==undefined){
        message.promptBox("用户未登录","warning")
      }else{
        sessionStorage.removeItem("token")
        message.promptBox("用户信息过期","warning")
      }

    }
  },
  actions: {
  },
  modules: {
  }
})
